package com.live.countline;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class CountFile implements CountInterface {

	private int codeLine = 0;
	private int note = 0;

	/**
	 * 
	 */
	public void parseJavaFile(String path) throws IOException {
		File file = new File(path);
		parseJavaFile(file);
	}

	/* */
	public void parseJavaFile(File file) throws IOException {

		BufferedReader reader = new BufferedReader(new FileReader(file));
		String t;
		boolean isNote = false;
		while (null != (t = reader.readLine())) {
			if (isNote) {
				note++;
			} else {
				t = t.trim();
				// 下面几种情况
				if (t.startsWith("//")) {
					note++;
				} else if (t.startsWith("/*")) {
					note++;
					isNote = true;
					if (t.endsWith("*/")) {
						isNote = false;
					}
				} else if (t.startsWith("*/")) {
					note++;
					isNote = false;
				} else {
					codeLine++;
				}
			}

		}
	}

	public void println() {

		System.out.println(codeLine + table + note);
	}

	public int getCodeLine() {
		return codeLine;
	}

	public int getNote() {
		return note;
	}

}
